let app = getApp()
Page({
  data: {
    navName: ['上传', '下载', '离线'],
    navIndex: 0,
    transferData: [{
        status: true,
        onGoing: [],
        finished: [{
          id: 3,
          name: "测试上传成功的文件",
          size: "1024MB",
          date: "2019年12月3日 22点32分",
          status: "已完成",
          type: "video",
          ext: '.jpg'
        }],
      },
      {
        status: true,
        onGoing: [],
        finished: [{
          id: 4,
          name: "测试下载成功的文件",
          size: "1024MB",
          date: "2019年12月3日 22点32分",
          status: "已完成",
          type: "photo",
          ext: '.jpg'
        }],
      },
      {
        status: false,
        onGoing: [],
        finished: [],
      }
    ]
  },

  onTabChange(e) {
    // 接受来自组件传递的参数
    this.setData({
      navIndex: e.detail.activedTab
    })
  },
  onLoad: function(options) {},
  onShow: function() {

    if (app.data.isFileUplaod) {
      let uploadTask = wx.uploadFile({
        url: 'http://127.0.0.1/bodhi/interface/upload.php',
        filePath: app.data.fileInfo.tempFiles[0].path,
        header: {
          'content-type': 'multipart/form-data'
        },
        formData: {
          'userid': wx.getStorageSync('userid'),
          'classifyid': 1,
          'filename': app.data.fileInfo.tempFiles[0].name
        },
        name: 'file',
        success(res) {
          console.log(res)
          app.data.isFileUplaod = false
        }
      })
      uploadTask.onProgressUpdate((res) => {
        let dateInfo = app.data.fileInfo.tempFiles[0]
        console.log('上传进度', res.progress)
        console.log('已经上传的数据长度', res.totalBytesSent)
        console.log('预期需要上传的数据总长度', res.totalBytesExpectedToSend)
        let obj =new Object({
          id: 1,
          name: dateInfo.name,
          status: true,
          type: dateInfo.type,
          size: dateInfo.size,
          progress: res.progress,
          speed: res.totalBytesSent,
        })
        
        this.setData({
          'transferData[0].onGoing[0]': obj
        })
        console.log(obj)
      })
    } else {
      console.log('没有文件上传信息')
    }


  },
})